package com.ruoyi.system.controller;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.security.annotation.InnerAuth;
import com.ruoyi.system.api.domain.SysUser;
import com.ruoyi.system.service.ISysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 用户信息内部Controller，实现远程feign接口com.ruoyi.system.api.RemoteSysUserService。
 * 
 * @author ruoyi
 * @date 2023-04-27
 */
@RestController
@RequestMapping("/inner/user")
public class SysUserInnerController
{
    @Autowired
    private ISysUserService sysUserService;

    /**
     * 查询用户信息列表
     */
    @InnerAuth
    @PostMapping("/list")
    public R<List<SysUser>> selectSysUserList(SysUser sysUser)
    {
        List<SysUser> list = sysUserService.selectUserList(sysUser);
        return R.ok(list);
    }

    /**
     * 获取用户信息详细信息
     */
    @InnerAuth
    @GetMapping(value = "/{userId}")
    public R<SysUser> selectSysUserByUserId(@PathVariable("userId") Long userId)
    {
        SysUser sysUser = sysUserService.selectUserById(userId);
        return R.ok(sysUser);
    }

    /**
     * 新增用户信息
     */
    @InnerAuth
    @PostMapping
    public R<Integer> insertSysUser(@RequestBody SysUser sysUser)
    {
        Integer result = sysUserService.insertUser(sysUser);
        return R.ok(result);
    }

    /**
     * 修改用户信息
     */
    @InnerAuth
    @PutMapping
    public R<Integer> updateSysUser(@RequestBody SysUser sysUser)
    {
        Integer result = sysUserService.updateUser(sysUser);
        return R.ok(result);
    }

    /**
     * 批量删除用户信息
     */
	@InnerAuth
	@DeleteMapping("/{userIds}")
    public R<Integer> deleteSysUserByUserIds(@PathVariable Long[] userIds)
    {
        Integer result = sysUserService.deleteUserByIds(userIds);
        return R.ok(result);
    }

}
